#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    int subarraySum(vector<int>& nums, int k) {
        unordered_map<int, int> hash;
        int sum = 0;
        int count = 0;
        hash[0]++;
        for (auto i : nums)
        {
            sum += i;
            int diff = sum - k;
            count += hash[diff];
            hash[sum]++;
        }
        return count;
    }
};